#include "stdafx.h"
#include "CRandom.h"

NAMESPACE_CORE_BEGIN

void _CRandom::Seed(UINT_32 uiSeed)
{
	srand(uiSeed);
}

float_32 _CRandom::GetRandomFloat32(float_32 fMin, float_32 fMax)
{
	return ((rand() % 10000) * 0.0001f * (fMax - fMin)) + fMin; 
}

int_32 _CRandom::GetRandomInt32()
{
	return rand();
}

int_32 _CRandom::GetRandomInt32(int_32 uiMin, int_32 uiMax)
{
	if(uiMin >= uiMax)
		return uiMin;
	else
		return uiMin + GetRandomInt32() % (uiMax - uiMin + 1);
}


char_16 _CRandom::GetRandomChar16(uint_x uiFlags/* =  = RAND_CHAR_ALL*/)
{
	int_32 iRandNum = _CRandom::GetRandomInt32() % 62;
	if(iRandNum < 10)
		return (char_16)(iRandNum + L'0');
	else if (iRandNum < 36)
		return (char_16)(iRandNum + L'a' - 10);
	else
		return (char_16)(iRandNum + L'A' - 36);
}

void _CRandom::GetRandomText(char_16 * szOut, uint_x uiMinLen/* = 0*/, uint_x uiMaxLen/* = 10*/)
{
	uint_x index = 0;
	for(uint_x cnt = 0; cnt != uiMinLen; ++cnt)
	{
		szOut[index++] = GetRandomChar16(RAND_CHAR_ALL);
	}

	if(uiMaxLen > uiMinLen)
	{
		int_32 iRandLen = _CRandom::GetRandomInt32() % ((int_32)(uiMaxLen - uiMinLen));
		for(int_32 cnt = 0; cnt != iRandLen; ++cnt)
		{
			szOut[index++] = GetRandomChar16(RAND_CHAR_ALL);
		}
	}
	szOut[index] = L'\0';
}

NAMESPACE_CORE_END
